// 店铺模型
const { Store, validateStore } = require('../../../models/store');
// 统一数据返回类
const { DataReturn } = require('../../../common/returnclass');

/**
 * @api {Put} /stores 修改商家店铺
 * @apiGroup Admin-Stores
 *
 * @apiParam {ObjectId} _id 店铺id
 * @apiParam {String} store_name  店铺名称
 * @apiParam {String} store_intro  店铺简介
 * @apiParam {Array} store_banner  店铺宣传照
 * @apiParam {ObjectId} store_cate  店铺商品分类
 * @apiParam {ObjectId} store_belong  店铺所属用户
 * @apiParam {Array} address  店铺地址
 * @apiParam {String} phone  联系电话
 * 
 * @apiSuccess {ObjectId} _id 店铺id
 * @apiSuccess {ObjectId} store_goods  店铺商品
 * @apiSuccess {String} store_name  店铺名称
 * @apiSuccess {String} store_intro  店铺简介
 * @apiSuccess {Array} store_banner  店铺宣传照
 * @apiSuccess {ObjectId} store_cate  店铺商品分类
 * @apiSuccess {ObjectId} store_belong  店铺所属用户
 * @apiSuccess {Array} address  店铺地址
 * @apiSuccess {String} phone  联系电话
 * @apiSuccess {Array} send_address  发货地址
 * @apiSuccess {String} add_time  添加时间
 * 
 * @apiSuccess {Number} code 状态码
 * @apiSuccess {Object} data 返回数据
 * @apiSuccess {String} msg  返回消息
 */
module.exports = async (req, res) => {
	console.log(req.fields);
	// 店铺id
	let { _id } = req.fields;
	
	// 数据格式校验
	const { error } = validateStore(req.fields);
	// 格式不符合要求
	if (error) return DataReturn.getData(res,400,[],error.message);
	// 保存店铺信息
	Store.updateOne({ _id}, req.fields)
	.then(()=>{
		DataReturn.getData(res,200,[],'更新店铺信息成功')
	}).catch(()=>{
		DataReturn.getData(res,400,[],'更新店铺信息失败')
	})

}
